/* 获取select元素 */
var provinceDOM = document.getElementById('province');
var cityDOM = document.getElementById('city');
var schoolDOM = document.getElementById('school');


/* 获取信息，填充到select的option中 */
for (let prop in province) {
    //prop:省市标号province[prop]：省市名称
    let optionDOM = document.createElement("option");
    optionDOM.value = prop;
    optionDOM.innerText = province[prop]; //不能用.操作符来获取；因为prop是字符串型
    provinceDOM.appendChild(optionDOM);
}

provinceDOM.onchange = function () {
    /* 清空cityDOM的内容 */
    cityDOM.innerText = '';
    /* 清空schoolDOM的内容 */
    schoolDOM.innerText = '';
    let lab = provinceDOM.value; //city下的编号
    //循环渲染城市列表
    cityObj = city[lab];
    if (cityObj == undefined) return;

    // console.log(cityObj);
    for (let prop in cityObj) {
        let optionDOM = document.createElement("option");
        optionDOM.value = prop;
        optionDOM.innerText = cityObj[prop]; //
        cityDOM.appendChild(optionDOM);
    }


    let c = cityDOM.value;
    var schoolArr = school[c];
    for (let i = 0; i < schoolArr.length; i++) {
        let optionDOM = document.createElement("option");
        optionDOM.innerText = schoolArr[i];
        schoolDOM.appendChild(optionDOM);
    }


}

cityDOM.onchange = function () {
    /* 清空schoolDOM的内容 */
    schoolDOM.innerText = '';
    let c = cityDOM.value;
    var schoolArr = school[c];
    for (let i = 0; i < schoolArr.length; i++) {
        let optionDOM = document.createElement("option");
        optionDOM.innerText = schoolArr[i];
        schoolDOM.appendChild(optionDOM);
    }
}